// ml:run = $bin < input
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n, m, cnt;
int a[200], sxor[200];
int b[20000];
int len[5000], mult[5000];
int main()
{
    int t;
    scanf("%d", &t);
    while(t--){
        memset(len, 0, sizeof(len));
        memset(mult, 0, sizeof(mult));
        cnt=0;
        scanf("%d", &n);
        a[0]=0;
        for (int i=1;i<=n;i++) scanf("%d", &a[i]);
        int now=0;
        for (int i=1;i<=n;i++){
            now = now ^ a[i];
            sxor[i]=now;
        }
        for (int i=1;i<=n;i++)
            for (int j=i;j<=n;j++){
                b[cnt++]=sxor[j] ^ sxor[i-1];
                len[b[cnt-1]]=max(len[b[cnt-1]], j-i+1);
            }
        sort(b, b+cnt);
        scanf("%d", &m);
        for (int i=0;i<m;i++){
            int x;
            scanf("%d", &x);
            int l=0, r=cnt-1, pos=-1;
            while(l<=r){
                int mid=(l+r)/2;
                if (x<=b[mid]){
                    pos=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            int ans;
            if (pos==-1){
                ans=b[cnt-1];
            }
            else if (pos==0){
                ans=b[0];
            }
            else{
                if (b[pos]-x>x-b[pos-1]) ans=b[pos-1];
                else if (b[pos]-x<x-b[pos-1]) ans=b[pos];
                else if (len[b[pos]]>len[b[pos-1]]) ans=b[pos];
                else ans=b[pos-1];
            }
            printf("%d\n", len[ans]);
        }
        printf("\n");
    }
    return 0;
}

